package com.dunqi.gpm.shunqing.home.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.dunqi.gpm.shunqing.R;
import com.dunqi.gpm.shunqing.common.base.RecyclerAdapter;
import com.dunqi.gpm.shunqing.common.util.TimeUtil;
import com.dunqi.gpm.shunqing.home.bean.Compared;
import com.dunqi.gpm.shunqing.home.bean.Problem;
import com.dunqi.gpm.shunqing.home.fragment.HomeFragment;
import com.dunqi.gpm.shunqing.home.widget.NormalView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 空 on 2017/12/5 0005.
 */
public class ProblemConsortAdapter extends RecyclerAdapter<Problem> {

    ArrayList<Compared> problemStatuss = new ArrayList<>();
    ArrayList<Compared> progressTypes = new ArrayList<>();

    public ProblemConsortAdapter(@Nullable List<Problem> data) {
        super(R.layout.item_problem_consort, data);

        initData();
    }


    @Override
    protected void convert(BaseViewHolder helper, Problem item) {
        TextView problemAuditTypeView = helper.getView(R.id.problem_audit_type_view);
        TextView problemTypeView = helper.getView(R.id.problem_type_view);
        TextView reportTimeView = helper.getView(R.id.report_time_view);
        TextView progressTypeView = helper.getView(R.id.progress_type_view);
        NormalView attachBranchView = helper.getView(R.id.attach_branch_view);
        NormalView reporterNameView = helper.getView(R.id.reporter_name_view);
        NormalView problemDesView = helper.getView(R.id.problem_des_view);
        NormalView problemSuggestview = helper.getView(R.id.problem_suggest_view);
        NormalView proNameView = helper.getView(R.id.pro_name_view);

        if (HomeFragment.homeMenuId == 18) {
            proNameView.setVisibility(View.VISIBLE);
            proNameView.setText(item.getProjectName());
        } else {
            proNameView.setVisibility(View.GONE);
        }


        int problemStatus = item.getProblemStatus();
        Compared compared = problemStatuss.get(problemStatus - 1);
        problemAuditTypeView.setText(compared.getDes());

        problemTypeView.setText(item.getProblemTypeText());

        String reportTime = item.getReportPeriod();
        if (!TextUtils.isEmpty(reportTime)) {
            reportTime = TimeUtil.getTen(reportTime);
            String[] split = reportTime.split("-");
            reportTimeView.setText(split[0] + "年" + split[1] + "月");
        }


        int progressType = item.getProgressType();
        String des = progressTypes.get(progressType).getDes();
        progressTypeView.setText(des);

        attachBranchView.setText(item.getInvolveDepartment());

        reporterNameView.setText(item.getReporterName());

        problemDesView.setText(item.getProblemDesc());

        problemSuggestview.setText(item.getMeasuresSuggestion());

//        int homeMenuId = HomeFragment.homeMenuId;
//        if (homeMenuId == 18) {
//            helper.setText(R.id.more_tv, "协调");
//        } else {
//            helper.setText(R.id.more_tv, "");
//        }

    }

    private void initData() {
        problemStatuss.add(new Compared(1, "未处理"));
        problemStatuss.add(new Compared(2, "已收集"));
        problemStatuss.add(new Compared(3, "协调中"));
        problemStatuss.add(new Compared(4, "已解决"));
        problemStatuss.add(new Compared(5, "不能解决"));
        problemStatuss.add(new Compared(6, "关闭"));

        progressTypes.add(new Compared(0, "未填写"));
        progressTypes.add(new Compared(1, "进展顺利"));
        progressTypes.add(new Compared(2, "基本正常"));
        progressTypes.add(new Compared(3, "进度滞后"));
        progressTypes.add(new Compared(4, "申请结项"));
    }
}
